// ----------------------------------------------------------------------
//  Jack McCaffery
//  11-20-2014
// ----------------------------------------------------------------------

#include "topicModel/basicData.H"

#include <QtTest/QtTest>


/// \brief test class for basicData class
class BasicData_test : public QObject
{

Q_OBJECT

private slots:

	/// \brief Initialize data for testing
	void initTestCase ();

	/// \brief Test file IO functionality
	void testFileIO ();

	/// \brief Cleanup after testing
	void cleanupTestCase ();

private:

	/// \brief A small dataset to test on
	BasicData<double> smallData;
};

void BasicData_test::initTestCase()
{
	smallData.getData ().resize (2, 3);

	smallData[0][0] = 1.0;
	smallData[0][1] = 2.5;
	smallData[0][2] = 3.0;
	smallData[1][0] = -3.0;
	smallData[1][1] = -2.5;
	smallData[1][2] = -1.0;
}

void BasicData_test::testFileIO()
{
	QString savename = "smallTest";

	// Save data
	smallData.save (savename);

	// Check that saving didn't break the data
	QVERIFY (smallData[0][0] == 1.0);
	QVERIFY (smallData[1][1] == -2.5);

	// Load the data
	BasicData<double> m;

	m.load (savename);

	QVERIFY (m == smallData);

	m.getData () (1, 1) = 10;

	QVERIFY (m != smallData);
}

void BasicData_test::cleanupTestCase()
{
	QString savename = "smallTest";

	QFile::remove (savename);
}


QTEST_MAIN (BasicData_test)
#include "basicData_test.moc"
